﻿function toJsArray(ori_data) {
    if (ori_data == null) return new Array();
    var rtn = new Array();
    for (var i = 0; i < ori_data.Length; i++) {
        var d = ori_data[i];
        var item = {};
        for (var j = 0; j < d.Keys.Length; j++) {
            var key = d.Keys[j];
            item[key] = d.GetValue(key);
        }
        rtn[i] = item;
    }
    return rtn;
}
function nvl(obj) {
    if (obj === null) return "";
    if (obj === undefined) return "";
    return obj.toString().trim();
}
function isNull(obj, default_v) {
    if (obj === null) return default_v;
    if (obj === undefined) return default_v;

    return obj;
}
String.prototype.split_no_empty = function (separator) {
    var arr = this.split(separator);
    var rtn = new Array();
    for (var i = 0; i < arr.length; i++) {
        if (nvl(arr[i]) != "") {
            rtn[rtn.length] = nvl(arr[i]);
        }
    }
    return rtn;
}
Array.prototype.where = function (whereFunc) {
    var rtn = [];
    for (var i = 0; i < this.length; i++) {
        if (whereFunc(this[i], i)) {
            rtn.push(this[i]);
        }
    }
    return rtn;
}
Array.prototype.firstOrDefault = function () {
    if (this.length <= 0) return null;
    return this[0];
}
Array.prototype.addRange = function (arr) {
    if (!arr) return;
    for (var i = 0; i < arr.length; i++) {
        this.push(arr[i])
    }
}